var do_Page = sm("do_Page");
var do_App = sm("do_App");
var nf = sm("do_Notification");
var openHelper = require("helper/open");
var communityUrl = require("url/community");
var communityUtil = require("helper/community");
var httpSilence = require("helper/http");
var userUtil = require("helper/user");
var listdata = mm("do_ListData");
//andriod返回键
do_Page.on("back", function() {
  do_App.closePage();
});
var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
  do_App.closePage()
});
var labelTitle = ui(addheader+".labelTitle");

labelTitle.text = "社区详情";
var communityId;
//页面装载完成后，开始初始化工作
do_Page.on("loaded", function() {
	//读取当前页面的传入参数
	var data=do_Page.getData();
	communityId=data.communityId;
	deviceone.print(communityId);
	var params = {
			id: communityId
		};
	ui("do_Label_42").visible = true;
	loadPage(params);
});
var resume=ui("resume");
var curUserCommunityId;
var currentHonorType = 0;
function loadPage(params) {
	
	httpSilence.post(communityUrl.url.base.detail, params, function(data) {
		try{
		ui("communityName").text=data.detail.name;
		}catch(e){;}
		curUserCommunityId=data.curUserCommunityId;
		try{
		resume.text=data.detail.resume;
	    }catch(e){;}
		ui("do_Label_circle_count").text=data.circleCount;
		ui("do_Label_neighbor_count").text=data.neighborCount;
		ui("do_Label_qShop_count").text=data.qShopCount;
		
		var levelImgs=["source://image/honor/num1.png","source://image/honor/num2.png","source://image/honor/num3.png"];
		var pvArr=["bfbfbfFF","a0afbcff","98acc4ff","ccaaa2ff","db8c71ff","e0c75fFF","ecc609FF"];
		for (var i = 0; i < data.users.length; i++) {
			if(i<3){
				data.users[i].isLevel = true;
				data.users[i].levelImg = levelImgs[i];
			}
			var level = data.users[i].honorLevel;
			data.users[i].honorLevelBg = pvArr[level];
		}
		ui("userList").items = data.users;
		
	})
}
//圈子更多
ui("do_ALayout_more_circle_1").on("touch", function(data) {
	openHelper.open("source://view/community/circle/list.ui");
});
//邻居更多
ui("do_ALayout_more_neighbor").on("touch", function(data) {
	if(userUtil.loginToken()==="undefined"||userUtil.loginToken()===""){
		nf.toast("请先登录再操作");
		openHelper.openLogin();
		return;
	}
	if(communityUtil.communityVisitId()==curUserCommunityId){//当前社区用户才能查看邻里
		openHelper.open("source://view/community/neighbor/newNeighborList.ui");
	}else{
		nf.toast("加入该社区，才能查看邻居。")
	}
});
//社区店铺
ui("do_ALayout_more_qShop").on("touch", function(data) {
	openHelper.open("source://view/qshop/comShop/main.ui");
});
//荣誉榜
ui("do_ALayout_Hi").on("touch", function(data) {
	openHelper.open("source://view/honor/list.ui",{honorType:currentHonorType});
});
//社区黄页
ui("do_ALayout_to_yellow").on("touch", function(data) {
	openHelper.open("source://view/community/yellow/index.ui");
});
//社区邻居动态
ui("do_ALayout_to_neighbor").on("touch", function(data) {
	openHelper.open("source://view/community/message/list.ui");
});
ui("do_Label_day").on("touch",function(data){
	var params = {
			id: communityId,
			rankType: 0
		};
	ui("do_Label_42").visible = true;
	ui("do_Label_43").visible = false;
	ui("do_Label_44").visible = false;
	ui("do_Label_45").visible = false;
	currentHonorType = 0;
	loadPage(params);
});

ui("do_Label_week").on("touch",function(data){
	var params = {
			id: communityId,
			rankType:1
		};
	ui("do_Label_42").visible = false;
	ui("do_Label_43").visible = true;
	ui("do_Label_44").visible = false;
	ui("do_Label_45").visible = false;
	currentHonorType = 1;
	loadPage(params);
});
ui("do_Label_month").on("touch",function(data){
	var params = {
			id: communityId,
			rankType:2
		};
	ui("do_Label_42").visible = false;
	ui("do_Label_43").visible = false;
	ui("do_Label_44").visible = true;
	ui("do_Label_45").visible = false;
	currentHonorType = 2;
	loadPage(params);
});
ui("do_Label_pro").on("touch",function(data){
	var params = {
			id: communityId,
			rankType:3
		};
	ui("do_Label_42").visible = false;
	ui("do_Label_43").visible = false;
	ui("do_Label_44").visible = false;
	ui("do_Label_45").visible = true;
	currentHonorType = 3;
	loadPage(params);
});